<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>附件地址列表</title>

    <link rel="stylesheet" href="/static/admin/css/public.css">

</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset id="searchFieldset_currentTableRenderId" class="table-search-fieldset">
            <legend>条件搜索</legend>
            <form class="layui-form layui-form-pane form-search">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">文章ID</label>
                    <div class="layui-input-inline">
                        <input id="c-subject_id" name="subject_id" data-search-op="=" value="" placeholder="请输入ID" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline" style="margin-left: 115px">
                <button type="submit" class="layui-btn layui-btn-normal" data-type="tableSearch" data-table="currentTableRenderId" lay-submit="" lay-filter="currentTableRenderId_filter"> 搜 索</button>
                <button type="reset" class="layui-btn layui-btn-primary" data-table-reset="currentTableRenderId"> 重 置 </button>
            </div></form></fieldset>



        <h3>附件地址列表</h3>
        <table id="tableId" class="layui-table layui-hide"  lay-filter="tableFilter"></table>
    </div>
</div>

<script type="text/html" id="toolbar">
    <button class="layui-btn layui-btn-sm layuimini-btn-primary" lay-event="ref"><i class="fa fa-refresh"></i> </button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" data-table-delete><i class="fa fa-trash-o"></i> 删除</button>
</script>
<script type="text/html" id="operat">
    <a  data-aid="{{d.subject_id}}" class="layui-btn layui-btn-xs detail" href="javascript:" title="文章详情" >文章详情</a>
    <a class="layui-btn layui-btn-success layui-btn-xs" href="javascript:" title="编辑" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" href="javascript:" title="删除" lay-event="del">删除</a>
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="sexDemo" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script src="/static/plugs/layui/layui.js"></script>
<script src="/static/delelement.js"></script>
<script>
    var userTable;
    var $;
    layui.use(["element",  "table", "form"], function () {
        let table = layui.table;
        let form = layui.form;
       $ = layui.jquery;
        userTable = table.render({
            elem: '#tableId',
            url: "{:addons_url('attachlink://admin/index')}",
            limit: 10,
            page: true,
            toolbar: true,
            toolbar: "#toolbar",
            even: true,
            height: 'full',
            cellMinWidth: 120,
            cols: [[
                {type: "checkbox", fixed: "left"},
                {field: "subject_id", title: "文章ID"},
                {field: "subject_title", title: "文章标题"},
                {field: "score", title: "需要积分"},
                {field: "remark", title: "备注"},
                {field: "status", title: "状态", templet: '#switchTpl', unresize: true},
                {title: "操作",  align: "center", fixed: "right", templet: "#operat"}
            ]]
        });
        form.on('submit(currentTableRenderId_filter)', function (data) {
            var dataField = data.field;
            var formatFilter = {},
                formatOp = {};
            $.each(dataField, function (key, val) {
                if (val !== '') {
                    formatFilter[key] = val;
                    var op = $('#c-' + key).attr('data-search-op');
                    op = op || '%*%';
                    formatOp[key] = op;
                }
            });
            table.reload('tableId', {
                page: {
                    curr: 1
                }
                , where: {
                    filter: JSON.stringify(formatFilter),
                    op: JSON.stringify(formatOp)
                }
            }, 'data');
            return false;
        });
        //监听性别操作
        form.on('switch(sexDemo)', function(obj){
            $.post("{:addons_url('attachlink://Admin/modify')}",{
                id:this.value,
                field:'status',
                value:obj.elem.checked===true?1:0
            },function (res) {
                if(res.code==1){
                    // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
                    layer.tips('设置成功', obj.othis);
                }
            });
            //
        });
        $('body').on('click', '.detail', function () {
            var aid=$(this).attr('data-aid');
            window.open('/html/'+aid+'.html');
        });

        form.on("submit(search)", function (data) {
            userTable.reload({
                where: data.field,
                page: {curr: 1}
            });
            return false;
        });


        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "ref":
                    userTable.reload();
                    break;
            }
        });
    })
    function showJobUrl(key) {
        layer.alert(window.location.host+"{:addons_url('collect://rule/collect')}?key="+key);
    }

    function copyRule(id) {
        $.post("{:addons_url('collect://rule/copy')}?id="+id,function (res) {
            if(res.code==1){
                userTable.reload();
            }
        });
    }
</script>
</body>
</html>
